import { ElMessage } from "element-plus";
import { v4 as uuidv4 } from "uuid";
import { LowCodeImp, SelectorImp, Component } from './'
const lowCodeInstance = Symbol("lowCodeInstance");

export class Selector implements SelectorImp {
    private [lowCodeInstance]: LowCodeImp;
    currentComponent!: Component;
    constructor(lowcode: LowCodeImp,) {
        this[lowCodeInstance] = lowcode as LowCodeImp
    }

    find(name: string): Selector | boolean {
        if (!this[lowCodeInstance]) {
            return false
        }
        let components: Component[] = Object.values(this[lowCodeInstance].dataCenter)
        let component = components.find(com => com.selector == name)
        this.currentComponent = component as Component
        return this

    }

    set(key: string, value: any): Selector {
        this.currentComponent.options[key] = value
        return this;
    }

    get(key?: string) {
        if (key) {
            return this.currentComponent.options[key]
        } else {
            return this.currentComponent.options
        }

    }

    open() {
        if (this.currentComponent) {
            this.currentComponent.options["visible"] = true
        } else {
            ElMessage.warning("弹框没找到哦！")
        }

    }

    close() {
        if (this.currentComponent) {
            this.currentComponent.options["visible"] = false
        } else {
            ElMessage.warning("弹框没找到哦！")
        }

    }
}